package com.example.crm.exception;

import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalExceptionHandler {
    //出现异常后跳转的方法
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request, UnauthorizedException e){

        ModelAndView mv=new ModelAndView("403");   //设置跳转路径
        mv.addObject("exception",e);//将异常对象传递出去
        mv.addObject("url", request.getRequestURL());//获得请求路径
        return mv;
    }
}
